/**
 * JAVACC DEMO 1.0
 */
package com.apache.portal.common.template.helper;

import com.apache.api.vo.ParamsVo;
import com.apache.info.entity.PubMetadata;
import com.apache.info.entity.PubSortInfo;
import com.apache.portal.common.template.FreemarkerHelper;
import com.apache.portal.common.util.FileOperate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * description:  生成属性实现类
 *
 * @author dyhou 创建时间：2016-9-30
 */
public class EntityTempManager extends SupperTemplateManager {

    public boolean createEntity(Map<String, Object> param) {
        boolean mark = false;
        List<PubSortInfo> list = (List<PubSortInfo>) param.get("sortList");
        String jarPath = String.valueOf(param.get("packPath"));
        String prefix = String.valueOf(param.get("projectName")) + "/src/main/";
        String xmlPath = String.valueOf(param.get("filePath")) + "/" + prefix + "java/" + jarPath
                .replace(".", "/") + "/entity/";
        FileOperate.getInstance().newCreateFolder(xmlPath);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("packPath", jarPath);
        try {
            ParamsVo vo = new ParamsVo();
            PubMetadata metadata = new PubMetadata();
            for (PubSortInfo map : list) {
                data.put("sort", map);
                metadata.setSortId(String.valueOf(map.getSortId()));
                vo.setObj(metadata);
                List mts = null;//(List) metadataManager.getList(vo);
                data.put("metadatas", mts);
                String result = FreemarkerHelper.instance()
                        .getTemplateStr(data, "entity/ObjName.inc");
                FileOperate.getInstance()
                        .newCreateFile(xmlPath + String.valueOf(map.getObjName()) + ".java",
                                result);
            }
            mark = true;
        } catch (Exception e) {
            log.error("生成实体失败", e);
        }
        return mark;
    }
}
